package cn.tworice.client.service;

import cn.tworice.admin.service.InductsListenerService;
import cn.tworice.client.dao.InfoDao;
import cn.tworice.common.entity.code.*;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InfoService implements InductsListenerService<Info> {
    @Autowired
    private InfoDao dao;

    public List<Info> getList(Integer page, Integer pageSize, Info entity) {
        return dao.queryList(page * pageSize, pageSize, entity);
    }

    public int getTotal(Info entity) {
        return dao.queryTotal(entity);
    }

    public void set(Info entity) {
        if (entity.getId() == null) {
            entity.setDate(System.currentTimeMillis());
            dao.insert(entity);
        } else {
            dao.update(entity);
        }
    }

    public void del(Integer[] ids) {
        dao.del(ids);
    }

    @Override
    public int save(List<Info> list) {
        list.forEach(item -> {
            item.setDate(System.currentTimeMillis());
        });
        return dao.insertList(list);
    }

    public void delBySacn(Integer[] ids) {
        dao.delBySacn(ids);
    }

    public List<Info> getListBySacn(long id) {
        Info info=new Info();
        info.setSacn(id);
        return dao.queryList(0, 100, info);
    }
}
